//
//  MTKRawCmdVC.swift
//  SDKDebuggingDemo
//
//  Created by 秦晟哲 on 2019/8/19.
//  Copyright © 2019 QinszQSZ. All rights reserved.
//

import UIKit


enum MTKCmd:String {
    //Unit
    case SET_35 = "SET,35"
        
    //AlarmClock
    case RET_GET_15 = "RET,GET,15"
    case SET_13 = "SET,13"
    case GET_15 = "GET,15"
        
    //Sleep
    case RET_GET_12 = "RET,GET,12"
    case RET_3 = "RET,3"
    case GET_12 = "GET,12"
    case RET_GET_13 = "RET,GET,13"
    case GET_13 = "GET,13"
    case GET_3 = "GET,3"

    //Camera
    case RET_SET_14 = "RET,SET,14"
    case SET_14 = "SET,14"

    //FindDevice
    case SET_40 = "SET,40"
    case FindDeviceNative = "FindDeviceNative"

    //Step
    case RET_2 = "RET,2"
    case RET_SEND_11 = "RET,SEND,11"
    case GET_2 = "GET,2"
    case GET_11 = "GET,11"
    case GET_10 = "GET,10"

    //PhoneState
    case SET_15 = "SET,15"
                                              
    //DeviceInfo
    case GET_0 = "GET,0"
        
    //Sport
    case GET_17 = "GET,17"
    case GET_18 = "GET,18"
    case RET_GET_18 = "RET,GET,18"
    case RET_GET_18_1 = "RET,GET,18,1"
        
    //Language
    case SET_44 = "SET,44"
        
    //QR
    case SET_22 = "SET,22"
        
    //SedentaryRemind
    case SET_12 = "SET,12"
    case RET_SET_12_1 = "RET,SET,12,1"
        
    //Time
    case SET_45 = "SET,45"
        
    //Dial
    case SETNEW_2 = "SETNEW,2"
    case GETNEW_1 = "GETNEW,1"
    case SETNEW_1 = "SETNEW,1"
    
    //Menstrual
    case SETNEW_3 = "SETNEW,3"
    
    //Pressure
    case GETNEW_2 = "GETNEW,2"
    case RET_GETNEW_2 = "RET,GETNEW,2,"

    //BloodOxygen
    case RET_GET_52 = "RET,GET,52"
    case GET_52 = "GET,52"
        
    //Gesture
    case SET_46 = "SET,46"
        
    //BloodPressure
    case SET_47 = "SET,47"
    case RET_GET_51 = "RET,GET,51"
    case GET_51 = "GET,51"
        
    //DrinkRmind
    case RET_SET_21_1 = "RET,SET,21,1"
    case SET_21 = "SET,21"
        
    //UserInfo
    case SET_10 = "SET,10"
        
    //Weather
    case SET_Weather = "SET,Weather"
    case SET_18 = "SET,18"
    case SETNEW_4 = "SETNEW,4"
    case GETNEW_3 = "GETNEW,3,"

    //HeartRate
    case RET_GET_14 = "RET,GET,14"
    case GET_14 = "GET,14"
    case SET_19 = "SET,19"
        
    //DevData
    case RET_1 = "RET,1"
    case GET_1 = "GET,1"
        
    //Invoice
    case SET_20 = "SET,20"
    
    //ECG
    case SET_16 = "SET,16"
    case SET_17 = "SET,17"
    case SET_18_ECG = "SET,18,ECG"
    case GET_20_ECG = "GET,20,ECG"
    
    //UNKNOW
    case UNKNOW = "UNKNOW"

}

class MTKRawCmdVC: UIViewController,UITableViewDataSource,UITableViewDelegate,KCTMTKShellDelegate {
    func mtkShell(scanPeripheral: CBPeripheral) {
        
    }
    

    @IBOutlet weak var reqTextView: UITextView!
    @IBOutlet weak var rspTextView: UITextView!
    
    private let tableView = UITableView.init()
    
    private let shell = KCTMTKShell.share
    
    private let cmdArray:[(String,MTKCmd)] = [
                                              
                    
                                              
                                             
  

               
                                              
                                                            

                                              // 天气
                                              ("设置天气",.SET_Weather),
                                              ("设置气象指数",.SET_18),
                                              ("设置天气1",.SETNEW_4),
                                              // 用户信息
                                              ("设置用户信息",.SET_10),
                                              // 单位
                                              ("设置单位",.SET_35),
                                              // 时间
                                              ("设置时间",.SET_45),
                                              // 久坐
                                              ("设置久坐提醒",.SET_12),
                                              // 喝水
                                              ("设置喝水提醒",.SET_21),
                                              // QR
                                              ("设置收款码",.SET_22),
                                              // App State
                                              ("设置前后台运行状况",.SET_15),
                                              // 语言
                                              ("设置语言",.SET_44),
                                              // 发票
                                              ("设置发票信息",.SET_20),
                                              // 手势
                                              ("设置手势功能",.SET_46),
                                              // 设备
                                              ("查询设备信息",.GET_0),
                                              ("查找设备(自定义)",.SET_40),
                                              ("查找设备(原生)",.FindDeviceNative),
                                              // 相机
                                              ("设置相机状态",.SET_14),
                                                // 闹钟
                                                ("设置闹钟",.SET_13),
                                                ("获取闹钟",.GET_15),
                                                // 血压
                                                ("获取历史血压",.GET_51),
                                                // 血氧
                                                ("获取历史血氧",.GET_52),
                                                // 心率
                                                ("获取心率",.GET_14),
                                                ("设置心率监测",.SET_19),
                                                // 运动
                                                ("获取运动数据索引",.GET_17),
                                                ("获取运动数据",.GET_18),
        // 表盘
        ("获取表盘推送支持信息",.GETNEW_1),
        ("设置表盘参数",.SETNEW_1),
        ("发送表盘",.SETNEW_2),
        // 生理周期
        ("设置生理周期",.SETNEW_3),
        // 精神压力
        ("精神压力",.GETNEW_2),
        // 计步
        ("获取每日记步",.GET_10),
        ("获取时间段记步",.GET_11),
        // 睡眠
        ("获取汇总睡眠",.GET_12),
        ("获取分段睡眠",.GET_13),
        // ECG
        ("设置是否在ECG心电界面 (SET,16)",.SET_16),
        ("设置ECG心电配置数据 (SET,17)",.SET_17),
        ("设置ECG心电状态 (SET,18)",.SET_18_ECG),
        ("获取ECG心电历史数据 (GET,20)",.GET_20_ECG),
                                              ]
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        
        tableView.delegate = self
        tableView.dataSource = self
        self.view.addSubview(tableView)
    }
    
    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        let width = self.view.frame.size.width
        let height = self.view.frame.size.height
        
        tableView.frame = CGRect.init(x: width - 150, y: reqTextView.frame.origin.y, width: 150, height: height - reqTextView.frame.origin.y)
    }
    
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        shell.delegate = self
    }

    @IBAction func clickBack(_ sender: Any) {
        self.navigationController?.popViewController(animated: true)
    }
    @IBAction func clickDisconnect(_ sender: Any) {
        shell.cancelConnection()
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return cmdArray.count
    }
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 60
    }
    
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        var cell = tableView.dequeueReusableCell(withIdentifier: "BLECmdCellID")
        if  cell == nil {
            cell = Bundle.main.loadNibNamed("BLECmdCell", owner: nil, options: nil)?.first as? BLECmdCell
        }
        
        let cmdCell = cell as! BLECmdCell
        cmdCell.titleLabel.text = cmdArray[indexPath.row].0 + "\n" + cmdArray[indexPath.row].1.rawValue
        return cmdCell
    }
    
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: false)
        
        rspTextView.text = nil
        
        let cmd = cmdArray[indexPath.row].1
        
        var cmdData = Data.init()
        switch cmd {
        case .GET_0:
            cmdData = KCTMTKCmds.GetDevInfo()
        case .GET_12:
            cmdData = KCTMTKCmds.GetSummarizedSleep()
        case .GET_13:
            cmdData = KCTMTKCmds.GetDetailSleep()
        case .SET_Weather://设置天气
            
            let phs = ["测试天气数据的个数","城市名称。eg. shenzhen"]
            
            self.showMultiTextInput(title: "天气设置", message: "推送从今天开始若干天的天气(测试数据)", lines: phs.count, placeHolders: phs) {[weak self] (contents) in
                if let count = Int(contents[0]){
                    
                    let cal = Calendar.current
                    let nowTS = Date.init().timeIntervalSince1970
                    let format = DateFormatter.init()
                    format.dateFormat = "yyyy-MM-dd"
                    
                    var ary = Array<MTKPushWeather>.init()
                    for i in 0 ..< count {
                        
                        let ts = nowTS + 60.0*60.0*24.0*Double(i)
                        let date = Date.init(timeIntervalSince1970: ts)
                        
                        let weather = MTKPushWeather.init()
                        weather.highTemperature = 30
                        weather.lowTemperature = 22
                        weather.weatherCode = 1
                        weather.week = cal.component(.weekday, from: date)
                        weather.dateString = format.string(from: date)
                        
                        ary.append(weather)
                    }
                    
                    if let data = KCTMTKCmds.SetWeather(city: contents[0], weathers: ary){
                        self?.shell.sendData(data: data)
                    }else{
                        SVProgressHUD.showInfo(withStatus: "输入有误")
                    }
                    
                }else{
                    SVProgressHUD.showInfo(withStatus: "填写有误")
                }
            }
        case .SET_18://设置气象指数
            if let data = KCTMTKCmds.SetWeatherIndex(pressure: 1, altitude: 1, UV: 1, temperature: 1, sunRiseTime: "09:00", sunSetTime: "19:00", RH: 1) {
                self.shell.sendData(data: data)
            }
        case .SETNEW_4://设置天气1
            let phs = ["测试天气数据的个数","城市名称。eg. shenzhen"]
            
            self.showMultiTextInput(title: "天气设置", message: "推送从今天开始若干天的天气(测试数据)", lines: phs.count, placeHolders: phs) {[weak self] (contents) in
                if let count = Int(contents[0]){
                    
                    let cal = Calendar.current
                    let nowTS = Date.init().timeIntervalSince1970
                    let format = DateFormatter.init()
                    format.dateFormat = "yyyy-MM-dd"
                    
                    var ary = Array<MTKPushWeather>.init()
                    for i in 0 ..< count {
                        
                        let ts = nowTS + 60.0*60.0*24.0*Double(i)
                        let date = Date.init(timeIntervalSince1970: ts)
                        
                        let weather = MTKPushWeather.init()
                        weather.highTemperature = 30
                        weather.lowTemperature = 22
                        weather.weatherCode = 1
                        weather.week = cal.component(.weekday, from: date)
                        weather.dateString = format.string(from: date)
                        
                        ary.append(weather)
                    }
                    
                    if let data = KCTMTKCmds.SetWeather1(temperature:32, weathers: ary){
                        self?.shell.sendData(data: data)
                    }else{
                        SVProgressHUD.showInfo(withStatus: "输入有误")
                    }
                    
                }else{
                    SVProgressHUD.showInfo(withStatus: "填写有误")
                }
            }
        case .SET_10://设置用户信息
            let phs = ["目标步数",
                       "性别(0-女，1-男)",
                       "身高(cm)",
                       "体重(kg)"]
            self.showMultiTextInput(title: "设置用户信息", message: nil, lines: phs.count, placeHolders: phs) {[weak self] (contents) in
                
                if let goal = Int(contents[0]), let sex = Int(contents[1]),let h = Int(contents[2]),let w = Int(contents[3]){
                    
                    let s = sex != 0 ? 1:0
                    
                    if let data = KCTMTKCmds.SetUserInfos(goal: goal, sex: s, height: h, weight: w) {
                        self?.shell.sendData(data: data)
                    }else{
                        SVProgressHUD.showInfo(withStatus: "输入有误")
                    }
                }else{
                    SVProgressHUD.showInfo(withStatus: "输入有误")
                }
            }
        case .SET_35://设置单位
            let phs = ["0-公制，1-英制","0-摄氏度，1-华氏度"]
            
            self.showMultiTextInput(title: "单位设置", message: nil, lines: phs.count, placeHolders: phs) {[weak self] (contents) in
                
                if let measure = Int(contents[0]),let temp = Int(contents[1]){
                    if let data = KCTMTKCmds.SetUnitSystem(measureType: measure, temperatureType: temp){
                        self?.shell.sendData(data: data)
                    }else{
                        SVProgressHUD.showInfo(withStatus: "输入有误")
                    }
                    
                }else{
                    SVProgressHUD.showInfo(withStatus: "输入有误")
                }
                
            }
        case .SET_45://设置时间
            let phs = ["0-24小时制，1-12小时制",
                       "时区。eg 8:东8区，-6:西6区",
                       "时间戳。秒"]
            
            let zone = TimeZone.current.secondsFromGMT()/60/60
            let ts = Int(Date.init().timeIntervalSince1970)
            
            let cs = ["0",
                      "\(zone)",
                      "\(ts)"]
            self.showMultiTextInput(title: "设置时间", message: nil, lines: phs.count, placeHolders: phs, contents: cs) {[weak self] (contents) in
                
                if let type = Int(contents[0]),let zone = Int(contents[1]), let ts = Int(contents[2]), let data = KCTMTKCmds.SetTime(use24Format: (type != 0), zone: zone, timestamp: ts) {
                    
                    self?.shell.sendData(data: data)
                    
                }else{
                    SVProgressHUD.showInfo(withStatus: "输入有误")
                }
            }
        case .SET_12://设置久坐提醒
            let phs = ["间隔(分)",
                       "0-关闭，1-开启",
                       "开始时间。 HH:mm",
                       "结束时间。HH:mm",
                       ]
            
            self.showMultiTextInput(title: "设置久坐提醒", message: nil, lines: phs.count, placeHolders: phs) {[weak self] (contents) in
                
                if let interval = Int(contents[0]), let openTag = Int(contents[1]) {
                    let start = contents[2]
                    let end = contents[3]
                    if let data = KCTMTKCmds.SetSedentaryReminder(time: interval, on: openTag, start: start, end: end){
                        self?.shell.sendData(data: data)
                    }else{
                        SVProgressHUD.showInfo(withStatus: "输入有误")
                    }
                } else {
                    SVProgressHUD.showInfo(withStatus: "输入有误")

                }
            }
        case .SET_21://设置喝水提醒
            let phs = ["间隔(分)",
                       "0-关闭，1-开启",
                       "开始时间。 HH:mm",
                       "结束时间。HH:mm",
                       ]
            
            self.showMultiTextInput(title: "设置喝水提醒", message: nil, lines: phs.count, placeHolders: phs) {[weak self] (contents) in
                
                if let interval = Int(contents[0]), let openTag = Int(contents[1]) {
                    let start = contents[2]
                    let end = contents[3]
                    if let data = KCTMTKCmds.SetDrinkReminder(time: interval, on: openTag, start: start, end: end){
                        self?.shell.sendData(data: data)
                    }else{
                        SVProgressHUD.showInfo(withStatus: "输入有误")
                    }
                } else {
                    SVProgressHUD.showInfo(withStatus: "输入有误")

                }
            }
        case .SET_22://设置收款码
            
            let phs = ["平台。0-支付宝，1-微信",
                       "二维码字符串。内容为空，则表示清除二维码"]
            
            self.showMultiTextInput(title: "设置收款码", message: nil, lines: phs.count, placeHolders: phs) {[weak self] (contents) in
                
                if let p = Int(contents[0]) {
                    
                    let qrStr = contents[1].count > 0 ? contents[1] : nil
                    
                    if let data = KCTMTKCmds.SetCollectionQR(platform: p, QRString: qrStr){
                        self?.shell.sendData(data: data)
                    }else{
                        SVProgressHUD.showInfo(withStatus: "二维码字符串UTF8编码失败")
                    }
                    
                }
            }
        case .SET_15://前后台运行状态
            self.showTextInput(title: "前后台运行状态", message: "0-后台，1-前台") { (text) in
                if let tag = Int(text){
                    let foreground = tag != 0
                    let data = KCTMTKCmds.SetPhoneState(runForeground: foreground)
                    self.shell.sendData(data: data)
                }else{
                    SVProgressHUD.showInfo(withStatus: "输入错误")
                }
            }
        case .SET_44://设置语言
            self.showTextInput(title: "设置语言", message: nil) {[weak self] (text) in
                if let data = KCTMTKCmds.SetLanguage(language: text){
                    self?.shell.sendData(data: data)
                }else{
                    SVProgressHUD.showInfo(withStatus: "UTF8编码失败")
                }
            }
        case .SET_20:// 设置发票
            self.showTextInput(title: "设置电子发票", message: "填写发票数量") {[weak self] (text) in
                if let count = Int(text), count >= 0 {
                    
                    var array = Array<MTKInvoice>.init()
                    
                    for i in 0 ..< count {
                        let invoice = MTKInvoice.init()
                        invoice.name = "抬头\(i)"
                        invoice.TFN = "TFN\(i)"
                        invoice.address = "地址\(i)"
                        invoice.phoneNum = "电话\(i)"
                        invoice.bankName = "银行\(i)"
                        invoice.bankAccount = "帐号\(i)"
                        invoice.remarks = "备注\(i)"
                        invoice.userId = 10000 + i
                        invoice.invoiceId = 20000 + i
                        invoice.defaultId = 30000 + i
                        
                        array.append(invoice)
                        
                    }
                    
                    if let cmdDatas = KCTMTKCmds.SetInvoices(invoinces: array) {
                        for i in 0 ..< cmdDatas.count {
                            self?.shell.sendData(data: cmdDatas[i])
                        }
                    }else{
                        SVProgressHUD.showInfo(withStatus: "输入有误")
                    }
                    
                    let tempArray = NSArray.init(array: array)
                    
                    self?.reqTextView.text = ReqContent(title: "设置发票", content: "\(tempArray.yy_modelToJSONObject() ?? "空")")
                    
                }else{
                    SVProgressHUD.showInfo(withStatus: "输入有误")
                }
            }
        case .SET_46://设置手势功能
            cmdData = KCTMTKCmds.SetGestureFunction(raiseSreenOn: true, flipHangUpPhone: false, mutAlarm: true, shakePaging: true, shakeAnswer: true)
        case .FindDeviceNative://查找设备
            cmdData = KCTMTKCmds.FindDeviceNativeProtocol()
        case .SET_40://查找设备
            cmdData = KCTMTKCmds.FindDevice(onoff: true)
        case .SET_14://相机状态
            self.showTextInput(title: "通知设备目前手机相机状态", message: "0-已关闭,1-已开启") {[weak self] (text) in
                if let tag = Int(text) {
                    let data = KCTMTKCmds.SetCamera(appCameraIsOn: tag != 0)
                    self?.shell.sendData(data: data)
                }else{
                    SVProgressHUD.showInfo(withStatus: "输入有误")
                }
            }
        //闹钟
        case .GET_15://获取闹钟
            cmdData = KCTMTKCmds.GetAlarmClock()
        case .SET_13://设置闹钟
            let ac = MTKAlarmClock.init();
            ac.time = "2021-01-18"
            ac.days = "0111111"
            ac.ring = 3
            ac.alertType = 2
            ac.flag = 1
            ac.type = 5
            let data = KCTMTKCmds.SetAlarmClock(acs: [ac])
            self.shell.sendData(data: data!)
        //血压
        case .GET_51:
            cmdData = KCTMTKCmds.GetBloodPressure()
        case .GET_52:
            cmdData = KCTMTKCmds.GetBloodOxygen()
        //心率
        case .GET_14:
            cmdData = KCTMTKCmds.GetHeartRate()
        case .SET_19://设置心率监测
            let phs = ["0-关闭，1-开启",
                       "开始时间。 HH:mm",
                       "结束时间。HH:mm",
                       "监测间隔(分)"]
            self.showMultiTextInput(title: "设置心率监测", message: nil, lines: phs.count, placeHolders: phs) {[weak self] (contents) in
                
                let startCmps = contents[1].components(separatedBy: ":")
                let endCmps = contents[2].components(separatedBy: ":")
                
                if startCmps.count > 1, endCmps.count > 1, let openTag = Int(contents[0]), let startH = Int(startCmps[0]),let startM = Int(startCmps[1]),let endH = Int(endCmps[0]),let endM = Int(endCmps[1]), let interval = Int(contents[3]){
                    if let data = KCTMTKCmds.SetHeartRateCheck(open: openTag != 0, startH: startH, startM: startM, endH: endH, endM: endM, interval: interval){
                        self?.shell.sendData(data: data)
                    }else{
                        SVProgressHUD.showInfo(withStatus: "输入有误")
                    }
                }else{
                    SVProgressHUD.showInfo(withStatus: "输入有误")
                }
            }
        // 运动
        case .GET_17:
            cmdData = KCTMTKCmds.GetSportIndexs()
        case .GET_18:

            self.showTextInput(title: "填写运动数据索引号", message: nil) {[weak self] (text) in
                if let index = Int(text){
                    let reqSportData = KCTMTKCmds.GetSport(index: index)
                    self?.shell.sendData(data: reqSportData!)
                }else{
                    SVProgressHUD.showError(withStatus: "填写有误")
                }
            }
        // 表盘
        case .GETNEW_1:
            cmdData = KCTMTKCmds.GetDialSupportInfo()!
        case .SETNEW_1:
            let data = KCTMTKCmds.SetDialParams(size: 666666)
            self.shell.sendData(data: data!)
        case .SETNEW_2:
            let dataT = NSData.init()
            let size = UInt16(dataT.count)
    //        size = CFSwapInt16HostToBig(size)  let signed   = Int8(bitPattern: UInt8(0xff)) // -> -1
            let crc = KCTCalculateTools.Crc32(srcData: dataT as Data)
            let cr1c = Int32(bitPattern: UInt32(crc))
            let data = KCTMTKCmds.SendDialParams(packetSum: 10, packetIndex: 1,size: size,crc: cr1c,data: dataT as Data)
            self.shell.sendData(data: data!)
        // 生理周期
        case .SETNEW_3:
            let data = KCTMTKCmds.SetMenstrual(date: "",
                                               continued: 0,
                                               cycle:  0,
                                               length: 0,
                                               remind: 0,
                                               moment: 0)
            self.shell.sendData(data: data!)
        // 精神压力
        case .GETNEW_2:
            let data = KCTMTKCmds.GetPressure()
            self.shell.sendData(data: data!)
        // 步数
        case .GET_10:
            cmdData = KCTMTKCmds.GetDailyStep()
        case .GET_11:
            cmdData = KCTMTKCmds.GetDeltaStep()
        // ECG
        case .SET_16:
            cmdData = KCTMTKCmds.SetECGView(bEcgView: 1)!
        default:
            SVProgressHUD.showInfo(withStatus: "未实现的CMD:\(cmd.rawValue)")
        }
        
        if cmdData.count > 0 {
            shell.sendData(data: cmdData)
        }
    }
    
    
    func mtkShellShakedHands(shell: KCTMTKShell) {
        IPrint("MTK握手成功")
    }
    func mtkShell(shell: KCTMTKShell, changeState state: Int32) {
        IPrint("MTK连接状态改变:\(state)")
    }
    func mtkShell(shell: KCTMTKShell, received cmd: String, message: NSObject?, error: KCTError?) {
        
        // 主动发来的数据
        var name = ""
        var className = ""
        switch cmd {
        case "SEND,10":// 记步
            name = "记步"
            className = "NSArray<MTKPedometerModel>"
            
        case "SEND,12"://实时心率
            name = "实时心率"
            className = "MTKHeartRate"
            
        case "SEND,51"://实时血压
            name = "实时血压"
            className = "NSArray<MTKBloodPressure>"

        case "SEND,52"://实时血氧
            name = "实时血氧"
            className = "NSArray<MTKBloodOxygen>"

        case "SET,40"://查找手机。停止查找:0, 开始查找:1, 未知错误:-1
            name = "查找手机"
            className = "NSNumnber(Int)"

        case "SET,10"://用户信息设置。在手表端设置了用户信息后，设备会将结果发送给手机
            name = "用户信息设置"
            className = "MTKUserInfos"

        case "SET,46"://设备主动发来的手势功能
            name = "手势功能设置"
            className = "MTKGestureFuncSettings"

        case "SET,47"://血压校准设置
            name = "血压校准"
            className = "MTKBPCalibrationSettings"
            
        case "SET,35"://单位设置(公制/英制转换)
            name = "单位设置"
            className = "MTKUnitsSystem"

        case "SET,17"://心电配置（设备进入心电应用后，会发送该指令给SDK）
            name = "心电配置"
            className = "MTKECGSettings"

        case "SEND,13"://实时心电
            name = "实时心电数据"
            className = "Array<MTKHisECGGroup>"

        case "SET,18"://实时心电开始/结束标记。0-结束,1-开始
            name = "实时心电开始/结束信号"
            className = "NSNumber(Int)"

        default:
            name = ""
            className = ""
        }
        
        if name.count > 0 {
            IPrint("收到设备主动上报的消息(\(name),\(className))")
        }else{
            // 请求指令与响应指令的对照，参考KCTMTKCmds中的注释或文档。
            IPrint("收到可能是设备发来的响应消息")
        }
        
        var des:Any?
        if let obj = message,let js = obj.yy_modelToJSONObject() {
            des = js
        }else{
            des = message
        }
        IPrint("MTKRawCmdVC:MTK收到解析后的消息:\ncmd=\(cmd)\nerror:\(error?.description ?? "无")\nmessage=\(des ?? "")")
        rspTextView.text = "[原始数据(UTF8解码)]:\ncmd=\(cmd)" + "\n\n" + "error:\n\(error?.description ?? "")" + "\n\n" + "message:\n\(des ?? "")"
        
    }
    
    override var preferredStatusBarStyle: UIStatusBarStyle{
        
        if #available(iOS 13.0, *){
            // 为了在不含darkContent的xcode版本上运行
            if let style =  UIStatusBarStyle.init(rawValue: 3) {
                return style
            }else{
                return .default
            }
        }else{
            return .default
        }
    }
    
}
